$(function () {
    //初始化专业搜索条件
    $.initSubject({
        element:'subject-box',
        confirmBtn:false,
        removeBtn: false,
        style:false,
        notMultiple:true,
        classText:'form-control mb10',
        width:100,
        selectCallback:function(subjectIds){
            $("#subjectIds").val(subjectIds);
        }
    });
    //加载课程数据
    listCourse(1);
    $("body").on('click', '#btn1,#btn2', function () { //搜索课程
        listCourse(1);
    });

    //加载课程数据
    function listCourse(page) {
        var params = $("#search-form").serializeJSON();
        params.subjectIds = $('input[name=subjectIds]').val();
        params = JSON.stringify(params);
        var obj = {
            url: baseloaction + '/admin/course/cou/ajaxSelectCourseList',//请求URL
            contextId: 'course-list-context',//响应内容页面设置内容ID
            params: params,//请求参数
            pageNo: page,//页码
            pageCall: listCourse, //分页回调加载数据(点击上下页时调用,该方法也在加载页面完成时调用)
            selectAllId: 'select-all-course', //全选框ID
            callback: function () {//数据加载完成回调
            }
        };
        ajaxGetListData(obj);
    }
});


/**
 * 获取选中课程
 */
function getSelectCourse() {
    var input = $('#course-list-context input.i-checks:checked');
    if (input.length == 0) {
        icModale(0, "请选择课程数据");
        return null;
    }
    var result = null;
    if (selectType == null || $.trim(selectType) == '' || typeof  selectType == 'undefined' || selectType == 'radio') {
        result = input[0];
        var _m = $(input[0]);
        var id = _m.val();
        var courseName = _m.attr("title");
        var orPrice = _m.attr("data-orprice");
        var subject = $('#subject-name-' + id).html();
        var image = _m.parents('tr').data('image');
        var courseTypeKey = _m.attr("data-courseTypeKey");
        result = {
            'id': _m.val(),
            'courseName': courseName,
            'orPrice': orPrice,
            'subject': subject,
            'image': image,
            'courseTypeKey':courseTypeKey
        };
    } else {
        result = new Array();
        $.each(input, function (index, _m) {
            _m = $(_m);
            var id = _m.val();
            var courseName = _m.attr("title");
            var orPrice = _m.attr("data-orprice");
            var subject = $('#subject-name-' + id).html();
            var image = _m.parents('tr').data('image');
            //console.log(subject);
            var _mould = {
                'id': _m.val(),
                'courseName': courseName,
                'orPrice': orPrice,
                'subject': subject,
                'image': image
            };
            result.push(_mould);
        });
    }
    return result;
}